package com.byedu.course.controller;

import com.byedu.domain.kaosi.Kaosi_QuestionDO;
import com.byedu.kaosi.KaoShiQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Luo on 2017-06-28.
 */
@Controller
public class KaoShiApiController {
    @Autowired
    private KaoShiQuestionService kaoShiQuestionService;


    /**
     	请求地址：http://jaad-app.cn/KaoShi/getAreas
     	请求方式：get
     	参数：无
     	返回：大区list<String>
     */
    @ResponseBody
    @RequestMapping("/getAreas")
    public String getAreas(HttpServletRequest request){
        String m = request.getParameter("m");
        if(StringUtils.isEmpty(m)){
            m = "user";
        }
        List<Kaosi_QuestionDO> kaoShiQuestionDOList = kaoShiQuestionService.getKaoShiQuestionDOList();
        request.setAttribute("m", m);
        request.setAttribute("kaoshiList", kaoShiQuestionDOList);
        return "kaosi/kaosilist";
    }

    @ResponseBody
    @RequestMapping("/login")
    public String login(@RequestParam(value = "area") String area, @RequestParam(value = "name") String name){
        List<Kaosi_QuestionDO> kaoShiQuestionDOList = kaoShiQuestionService.getKaoShiQuestionDOList();

        return "kaosi/addkaosi";
    }

    @ResponseBody
    @RequestMapping("/getUserRank")
    public String getUserRank(HttpServletRequest request){
        String m = request.getParameter("m");
        List<Kaosi_QuestionDO> kaoShiQuestionDOList = kaoShiQuestionService.getKaoShiQuestionDOList();
        request.setAttribute("m", m);
        request.setAttribute("kaoshiList", kaoShiQuestionDOList);
        return "kaosi/addkaosi";
    }

    @ResponseBody
    @RequestMapping("/getAreaRank")
    public String getAreaRank(HttpServletRequest request){
        String m = request.getParameter("m");
        List<Kaosi_QuestionDO> kaoShiQuestionDOList = kaoShiQuestionService.getKaoShiQuestionDOList();
        request.setAttribute("m", m);
        request.setAttribute("kaoshiList", kaoShiQuestionDOList);
        return "kaosi/addkaosi";
    }
    @ResponseBody
    @RequestMapping("/getIntro")
    public String getIntro(HttpServletRequest request){
        String m = request.getParameter("m");
        List<Kaosi_QuestionDO> kaoShiQuestionDOList = kaoShiQuestionService.getKaoShiQuestionDOList();
        request.setAttribute("m", m);
        request.setAttribute("kaoshiList", kaoShiQuestionDOList);
        return "kaosi/addkaosi";
    }

    @ResponseBody
    @RequestMapping("/startTest")
    public String startTest(@RequestParam(value = "userId") String userId){
//        String m = request.getParameter("m");
//        List<KaoShiQuestionDO> kaoShiQuestionDOList = kaoShiQuestionService.getKaoShiQuestionDOList();
//        request.setAttribute("m", m);
//        request.setAttribute("kaoshiList", kaoShiQuestionDOList);
        return "kaosi/addkaosi";
    }

    @ResponseBody
    @RequestMapping("/submitAnwser")
    public String submitAnwser(@RequestParam(value = "userId") String userId){
//        String m = request.getParameter("m");
//        List<KaoShiQuestionDO> kaoShiQuestionDOList = kaoShiQuestionService.getKaoShiQuestionDOList();
//        request.setAttribute("m", m);
//        request.setAttribute("kaoshiList", kaoShiQuestionDOList);
        return "kaosi/addkaosi";
    }
}
